This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
summary(cars)## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
Help > Cheatsheets > R Markdown Cheatsheet
“Pandoc’s Markdown”
Rmd filesLiterate Programming: interweaving code, its output, and regular prose text
File > New File > R Markdown …
Rmd File---
title: 'Back to Basics'
subtitle: 'R you markDown?'
author: "Daniel Chen"
date: "June 26, 2017"
output:
revealjs::revealjs_presentation:
theme: "night"
highlight: "zenburn"
css: styles.css
self_contained: true
reveal_options:
slideNumber: true
previewLinks: true
---revealjs: http://rmarkdown.rstudio.com/revealjs_presentation_format.html
```{r eval=TRUE}
n = 10
rnorm(n)
```
n = 10
rnorm(n)## [1] -0.64019032 0.60136155 -0.17928616 0.83450370 0.55648524
## [6] -0.80748120 0.44146987 -0.01113623 0.80593002 1.52699277
The previous slide showed random draws from the normal distribution with mean = 0 and sd = 1.
There were 10 draws.
We can either
nn in an r chunk.print(n)## [1] 10
```{r}
# R code here
```
```{r chunk_name}
# R code here
```
```{r chunk_name, echo = TRUE}
# R code here
```
The knit button (ctrl + shift + k)
rmarkdown::render(input,
output_format = NULL, output_file = NULL, output_dir = NULL,
output_options = NULL, intermediates_dir = NULL,
knit_root_dir = NULL,
runtime = c("auto", "static", "shiny", "shiny_prerendered"),
clean = TRUE,
params = NULL,
knit_meta = NULL, envir = parent.frame(),
run_pandoc = TRUE, quiet = FALSE, encoding = getOption("encoding"))DEMO 01-parameters
---
title: "parameters"
author: "Daniel Chen"
date: ""
output: html_document
params:
data: ""
---```{r}
rmarkdown::render(input = '01-parameters/params.Rmd',
quiet = TRUE,
params = list(
data = 'cars'
))
```pandoc pandoc-citeprocRscript -e "rmarkdown::render(input = '01-parameters/params.Rmd',
params = list(data = 'mtcars'))"books
http://rmarkdown.rstudio.com/r_notebooks.html
output: html_document -> output: html_notebook
.nb.htmlDEMO 02-notebook
library(DBI)
library(RSQLite)
rm(list = ls())
con = dbConnect(SQLite(), dbname = "data/survey.db")```{sql connection=con}
SELECT * from Person;
```
SELECT * from Person;| id | personal | family |
|---|---|---|
| dyer | William | Dyer |
| pb | Frank | Pabodie |
| lake | Anderson | Lake |
| roe | Valentina | Roerich |
| danforth | Frank | Danforth |
```{sql connection=con, output.var=df_sql}
SELECT * from Person;
```
name = 'William'```{sql connection=con, output.var=df_sql}
SELECT * from Person WHERE personal = ?name;
```
install.packages('revealjs'))output:
revealjs::revealjs_presentationMarkdown documents can also render HTML!
It’s how I make a 2-column slide
.column-left2{
float: left;
width: 50%;
text-align: left;
}
.column-right2{
float: right;
width: 50%;
text-align: left;
}<div class="column-left2">
<center>
Hello
</center>
</div>
<div class="column-right2">
<center>
there!
</center>
</div>DEMO 03-shiny_docs
ui codeserver code is not in a functionYou can also have shiny apps run in a presentation like this!
No demo though.
http://rmarkdown.rstudio.com/flexdashboard/
---
title: "Row Orientation"
output:
flexdashboard::flex_dashboard
---devtools::install_github('rstudio/blogdown')
blogdown::install_hugo()blogdown::new_site()
blogdown::serve_site()books: https://bookdown.org/
install.packages("bookdown")devtools::install_github("rstudio/bookdown")
DEMO 05-bookdown/01-minimal
---
title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: book
output:
bookdown::gitbook: default
bookdown::pdf_book: default
---
# Hello World
Hi.
Bye.
bookdown::render_book('index.Rmd', 'all')
rendered book will be under _book
bookdown::render_book('index.Rmd', 'all')
“Knit and Merge” (K-M): new_session = TRUE or new_session: yes
K-M does not allow Rmd files to be in subdirectories, but M-K does.
revert back to the notebook’s directory once the chunk is finished executing
knitr root.dir option
knitr::opts_knit$set(root.dir = normalizePath(".."))if (interactive()){
data_dir <- './data'
} else {
data_dir <- '../data'
}feedback needed: https://github.com/chendaniely/rendR
sweave and knitr:sweave child documents example: